import * as nodeFileSys from "fs";
import * as nodePath from "path";
import { ROOT_DIR } from "./global-helper";

Promise.all([
  nodeFileSys.promises.readFile(
    nodePath.join(ROOT_DIR, "./result/pin-yin-list.json"),
    "utf8"
  ),
  nodeFileSys.promises.readFile(
    nodePath.join(ROOT_DIR, "./result/py-pin-yin.json"),
    "utf8"
  ),
]).then(([jsResultString, pyResultString]) => {
  const pyResult = JSON.parse(pyResultString);
  const jsResult = JSON.parse(jsResultString);
  jsResult.forEach((item: any, index: any) => {
    if (item.word !== pyResult[index]) {
      let matchIndex: any = -1;
      for (let wordIndex in pyResult) {
        if (pyResult[wordIndex] === item.word) {
          matchIndex = wordIndex;
        }
      }
      let matchOne = jsResult.find((jsItem: any) => jsItem.word === pyResult[index])
      let jsIndex = matchOne ? matchOne.index : -1;
      console.log(index, item.index, item.word, pyResult[index], matchIndex, jsIndex);
    }
  });
});
